package com.server.questionbank.snframe.service.QuestionBank.Impl;

import com.server.questionbank.snframe.domain.User.UansRecord;
import com.server.questionbank.snframe.mapper.QuestionBank.UansRecordMapper;
import com.server.questionbank.snframe.service.QuestionBank.UansRecordService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UansRecordServiceImpl implements UansRecordService {
    @Autowired
    private UansRecordMapper uansRecordMapper;

    /**
     * 新增答题记录
     * @param record
     * @return
     */
    @Override
    public int createRecord(UansRecord record) {
        // 设置默认提交时间为当前时间
        record.setSubmitTime(new Date());
        // 设置默认答题状态为"已提交"
        if (record.getAnswerStatus() == null) {
            record.setAnswerStatus("已提交");
        }
        return uansRecordMapper.insertUansRecord(record);
    }

    /**
     * 修改答题记录
     * @param record
     * @return
     */
    @Override
    public int updateRecord(UansRecord record) {
        return uansRecordMapper.updateUansRecord(record);
    }

    /**
     * 查询答题记录
     * @param recordId
     * @return
     */
    @Override
    public UansRecord getRecordById(Long recordId) {
        return uansRecordMapper.selectById(recordId);
    }

    /**
     * 根据用户获取答题列表
     * @param userId
     * @return
     */
    @Override
    public List<UansRecord> getRecordsByUserId(Long userId) {
        return uansRecordMapper.getRecordsByUserId(userId);
    }
}
